import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

@SuppressWarnings("hiding")
interface GeneralStack<T>{
	public T push(T item);
	public T pop(); 
	public T peek(); 
	public boolean empty(); 
	public int size(); 
}
class ArrayListGeneralStack<T> implements GeneralStack<T>{
	ArrayList<T> list;
	public ArrayListGeneralStack(){
		list=new ArrayList<T>();
	}
	public T push(T item){
		//如果item为null，则不入栈直接返回null。如果栈满，也返回null。如果插入成功，返回item。
		if(item==null){
			return null;	
		}
		else {
    		list.add(item);
    			return item;
			
		}
 	}
	public T pop(){
		//出栈，如果为空，则返回null。出栈时只移动栈顶指针，相应位置不置为null
		if(empty()){
		      return null;
		}
		else {
		  	T elem=list.remove(list.size()-1);
			return elem;
			
		}
        }
	public T peek(){
		//获得栈顶元素，如果为空，则返回null.
		if(empty()){
		      return null;
		}
		else {
			return list.get(list.size()-1);
	    }
	}
	public boolean empty(){
		//如果为空返回true
		if(list.isEmpty()){
		  return true;
		}
		else return false;
	}
	public int size(){
		//返回栈中元素个数
	   return list.size();
	}
	@Override
	public String toString() {
		return list.toString();
	}
	
}
class Car11{
	private int id;
	private String name;
	
	public Car11(int id, String name) {
		super();
		this.id = id;
		this.name = name;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Override
	public String toString() {
		return "Car [id=" + id + ", name=" + name + "]";
	}
	
}

public class GeneralStack_pta555 {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		String str=in.next();
		while(in.hasNext()){
		if(str.equals("quit")){
			System.exit(0);
		}
		else if(str.equals("Integer")){
			int m=in.nextInt();
			int n=in.nextInt();
			ArrayListGeneralStack<Integer> stack=new ArrayListGeneralStack<Integer>();
			
			for (int i = 0; i < m; i++) {
				System.out.println("push:"+stack.push(in.nextInt()));
			}
			System.out.println("Integer Test");
			for (int i = 0; i < n; i++) {
				System.out.println("pop:"+stack.pop());
			}
			int sum=0;
			for (int i = 0; i <m-n ; i++) {
				sum+=stack.peek();
				System.out.println(stack.pop());
			}
			System.out.println("sum="+sum);
			System.out.println(stack.getClass().getInterfaces()[0]);
		}
		else if(str.equals("Double")){
			int m=in.nextInt();
			int n=in.nextInt();
			ArrayListGeneralStack<Double> stack=new ArrayListGeneralStack<Double>();
			
			for (int i = 0; i < m; i++) {
				System.out.println("push:"+stack.push(in.nextDouble()));
			}
			System.out.println("Double Test");
			for (int i = 0; i < n; i++) {
				System.out.println("pop:"+stack.pop());
			}
			double sum=0;
			for (int i = 0; i <m-n ; i++) {
				sum+=stack.peek();
				System.out.println(stack.pop());
			}
			System.out.println("sum="+sum);
			System.out.println(stack.getClass().getInterfaces()[0]);
		}
		else if(str.equals("Car")){
			int m=in.nextInt();
			int n=in.nextInt();
			ArrayListGeneralStack<Car11> stack=new ArrayListGeneralStack<Car11>();
			Car11[] cars=new Car11[m];
			for (int i = 0; i < cars.length; i++) {
				cars[i]=new Car11(in.nextInt(),in.next());
			}
			System.out.println("Car Test");
			for (int i = 0; i < m; i++) {
				System.out.println("push:"+stack.push(cars[i]));
			}
			for (int i = 0; i < n; i++) {
				System.out.println("pop:"+stack.pop());
			}
			for (int i = 0; i <m-n ; i++) {
				System.out.println(stack.pop());
				System.out.println(cars[i].getName);
			}
			
			System.out.println(stack.getClass().getInterfaces()[0]);
		}

	}
	}
}
